package com.proj.hot.utils;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import java.io.ByteArrayOutputStream;
import java.io.File;

/**
 * Created by zangchenggang on 17/6/26.
 */
public class BitmapUtil {
    /**
     * 读取图片文件
     *
     * @param path
     * @return
     */
    public static Bitmap readPic(String path) {
        Bitmap bitmap = null;
        File file = new File(path);
        if (file.exists())
            bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
        return bitmap;
    }

    /**
     * Bitmap 转byte[]
     *
     * @param bm
     * @return 返回字节数组
     */
    public static byte[] Bitmap2Bytes(Bitmap bm) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
        // Log.i("AAAAA",":::"+ baos.toByteArray().length);
        return baos.toByteArray();
    }
}
